<?php
// Pour imprimer et éditer un texte modifiable
function printEditItem($service, $file){
	// sauvegarde
	if(isset($_GET['save']) and ($file==$_GET['file'])){
		if (!$fp = fopen($_GET['file'],"w")) {echo "Echec de l'ouverture du fichier"; exit;}
		else {
			fputs($fp, $_POST['editor']);
			echo 'Texte sauvegardé ';
		}
	}
	// modif
	if (isset($_SESSION['login']) and !isset($_GET['edit'])) {
		echo '<a rel="superbox[ajax][editText.php?'.$service.'][750x400]" style="color:red" href="editText.php">Modifier le texte</a> ';
	}
	// affichage texte
	if (!isset($_GET['edit'])) echo file_get_contents($file);
	// édition
	if (isset($_SESSION['login']) and isset($_GET['edit'])){
			echo '<form action="?'.$service;
			echo '&amp;save=on" method="post">';
			echo '<p><textarea class="ckeditor" cols="80" id="editor" name="editor" rows="50">'."\n";
				// Transformation texte pour validation du HTML
			$content = file_get_contents($file);
			$find = array('<', '>');
			$replace = array('&lt;', '&gt;');
			echo str_replace($find, $replace, $content);
			echo '</textarea></p>'."\n";
			echo '<p><input type="submit" value="Sauvegarder"/></p>'."\n";
			echo '</form>'."\n";
	}
}

function imageDisplay($doc, $text){
	echo '	<table summary="image"><tr><td style="vertical-align:top;">'."\n";
	echo '		<a class="fieldArt" rel="superbox[iframe][920x920]" title="Image" target="_blank" href="'.$doc.'">'."\n";
	echo '		<img src="'.$doc.'" alt="image"  width="80" height="60"/>'."\n";
	echo '		</a>'."\n";
	echo '	</td><td style="vertical-align:top;">'."\n";
	$service = 'w=on&amp;u=on&amp;file='.$text;
	printEditItem($service, $text, '');
	echo '	</td></tr></table>'."\n";
}
?>
<h3 class="titreForm"><?php echo $menu['w']['desc'] ?></h3>
<?php include('rMenu.php'); ?>
<div class="column-left" style="width:68em;">
	<h3 class="titreForm">Quelques documents photographiques :</h3>

<?php
imageDisplay('../repository/doc003.jpg', '../repository/doc003.txt');
imageDisplay('../repository/doc005.png', '../repository/doc005.txt');
imageDisplay('../repository/doc008.jpg', '../repository/doc008.txt');
imageDisplay('../repository/doc009.jpg', '../repository/doc009.txt');
imageDisplay('../repository/doc004.jpg', '../repository/doc004.txt');
imageDisplay('../repository/doc002.gif', '../repository/doc002.txt');
imageDisplay('../repository/doc001.gif', '../repository/doc001.txt');
imageDisplay('../repository/doc006.png', '../repository/doc006.txt');
imageDisplay('../repository/doc007.png', '../repository/doc007.txt');
imageDisplay('../repository/doc012.jpg', '../repository/doc012.txt');
imageDisplay('../repository/doc010.jpg', '../repository/doc010.txt');
//imageDisplay('../repository/doc011.jpg', '../repository/doc011.txt');
?>


</div>
